package controllers;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import dao.AbstractDAO;

public class AbstractService<T extends Serializable> {
	protected AbstractDAO<T> dao;
	
	@RequestMapping(method=RequestMethod.GET)
	public @ResponseBody List<T> getAll(){
		return dao.getAll();
	}
	
	@RequestMapping(method=RequestMethod.PUT)
	public @ResponseBody T saveAll(@RequestBody T object){
		return dao.save(object);
	}
	
	@RequestMapping(method=RequestMethod.DELETE)
	public @ResponseBody Boolean deleteAuto(@RequestBody T object){
		return dao.delete(object);
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public @ResponseBody T updateAuto(@RequestBody T object){
		return dao.update(object);
	}
	
	
	@Required
	public void setDao(AbstractDAO<T> persistence) {
		this.dao = persistence;
	}
}
